/**
 * 用户模块
 */
import { login } from "@/api/sys";
import { getToken, setToken, clearCache } from "@/utils/cache";
import router from '@/router'

const Types = {
  SET_TOKEN: "SET_TOKEN",
  SET_USERINFO: "SET_USERINFO",
  SET_PROJECT_ID: "SET_PROJECT_ID",
  SET_PROJECT_LIST: "SET_PROJECT_LIST",
};

export default {
  namespaced: true,
  state: () => ({
    token: getToken() || "",
  }),
  mutations: {
    [Types.SET_TOKEN](state, token) {
      state.token = token;
      setToken(token);
    },
  },
  actions: {
    login(context, userInfo) {
      const { username, password } = userInfo;
      return new Promise((resolve, reject) => {
        // login({ username, password })
        //   .then((data) => {
        //     context.commit(Types.SET_TOKEN, "");
        //     resolve();
        //   })
        //   .catch((err) => {
        //     reject();
        //   });
      });
    },
    logout() {
      // resetRouter()
      this.commit('user/setToken', '')
      this.commit('user/setUserInfo', {})
      clearCache()
      router.push('/login')
    }
  },
};
